<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>修改员工信息</title>
    {% load static %}
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/static/css/oksub.css">
    <script type="text/javascript" src="/static/lib/loading/okLoading.js"></script>
    <script src="/static/lib/layui/layui.js"></script>

    <link type="text/css" rel="stylesheet" href="/static/css/metroStyle.css">
    <link type="text/css" rel="stylesheet" href="/static/css/treeSelectStyle.css">
    <script src="/static/js/jquery-1.11.2.min.js"></script>
    <script type="text/javascript" src="/static/js/jquery.ztree.all.js"></script>
    <script type="text/javascript" src="/static/js/treeSelect.2.0.js"></script>
    <script type="text/javascript" src="/static/js/xm-select.js"></script>
</head>
<body>
<div class="ok-body">
    <!--form表单-->
   <form class="layui-form layui-form-pane ok-form">
        <div class="layui-row layui-col-space10">
            <div class="layui-inline layui-col-md6">
                <label class="layui-form-label">客户代码<span style="color: red">*</span></label>
                <div class="layui-input-block">
                    <input type="text" id="cus_code" name="cus_code" placeholder="请输入被审单位代码(唯一)/18位"
                           lay-verify="required" maxlength="18" autocomplete="off" class="layui-input">
                    <input type="text" name="id" id="id" class="layui-input" style="display: none">
                </div>
            </div>
            <div class="layui-inline layui-col-md6">
                <label class="layui-form-label">客户名称<span style="color: red">*</span></label>
                <div class="layui-input-block">
                    <input type="text" id="cus_audited_object" name="cus_audited_object" placeholder="请输入被审单位名称"
                           lay-verify="required" autocomplete="off" class="layui-input">
                </div>
            </div>
        </div>
        <div class="layui-row layui-col-space10" style="padding-top: 10px;">
            <div class="layui-inline layui-col-md6">
                <label class="layui-form-label">联系电话<span style="color: red">*</span></label>
                <div class="layui-input-block">
                    <input type="tel" id="cus_phone" name="cus_phone" lay-verify="required|phone" placeholder="请输入联系人号码"
                           autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-inline layui-col-md6">
                <label class="layui-form-label">详细地址<span style="color: red">*</span></label>
                <div class="layui-input-block">
                    <input type="text" name="cus_address" id="cus_address" lay-verify="required" placeholder="请输入被审单位地址！"
                           autocomplete="off"
                           class="layui-input">
                </div>
            </div>
        </div>
        <div class="layui-row layui-col-space10" style="padding-top: 10px;">
            <div class="layui-inline layui-col-md6">
            <label class="layui-form-label">状态<span style="color: red">*</span></label>
            <div class="layui-input-block" id="LAY-switch-check">
                <input type="checkbox" id="now_status" name="now_status" lay-skin="switch" lay-filter="switchTest"
                       lay-text="启用|停用" checked="">
            </div>
            </div>
        </div>
        <div class="layui-form-item layui-form-text" style="padding-top: 10px;">
            <label class="layui-form-label">备注</label>
            <div class="layui-input-block">
                <textarea name="remark_describe" id="remark_describe" placeholder="请输入备注内容/140个汉字" maxlength="255" class="layui-textarea"></textarea>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="edit">立即提交</button>
                <button type="reset" id="close" class="layui-btn layui-btn-primary">关闭</button>
            </div>
        </div>
    </form>
</div>
<!--js逻辑-->

<script type='text/javascript'>
    var data1;
    function child(d) {
        data1 = d;
    layui.use(["form", "okUtils","jquery", "okLayer"], function () {
        var $ = layui.jquery;
        var form = layui.form;
        var okUtils = layui.okUtils;
        var okLayer = layui.okLayer;
        okLoading.close();
        $('#id').val(data1.id);
        $('#cus_code').val(data1.cus_code);
        $('#cus_audited_object').val(data1.cus_audited_object);
        $('#cus_phone').val(data1.cus_phone);
        $('#now_status').val(data1.now_status);
        $('#cus_address').val(data1.cus_address);
        $('#remark_describe').val(data1.remark_describe);
        form.render();
        if (data1.now_status === 0) {
            layui.jquery('input[name="now_status"]').attr('checked', 'checked');
            layui.jquery('input[name="now_status"]').next().addClass('layui-form-onswitch'); //开
        } else {
            layui.jquery('input[name="now_status"]').removeAttr('checked');
            layui.jquery('input[name="now_status"]').next().removeClass('layui-form-onswitch'); //关
        }
        // 监听switch状态
        form.on("switch(switchTest)", function (obj) {
            $(obj.elem).attr('type', 'hidden').val(this.checked ? 0 : 1);
            form.render();
        });
        // 这里得把switch的状态弄对，不然，如果他创建就停用，数据就传不过去了
        form.on("submit(edit)", function (data) {
            okUtils.ajax("/business/customers_edit/" + data.field.id, "post", data.field, true).done(function (response) {
                okLayer.greenTickMsg(response.msg, function () {
                    parent.layui.table.reload('tableId');
                    parent.layer.close(parent.layer.getFrameIndex(window.name));
                });
            }).fail(function (error) {
                // 这里已经有提示了
            });
            return false;
        });
        $('#close').click(function () {
            parent.layui.table.reload('tableId');
             parent.layer.close(parent.layer.getFrameIndex(window.name));
        });
    })}
</script>
</body>
</html>
